package com.hongkzh.www.look.view.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hongkzh.www.R;
import com.hongkzh.www.look.model.bean.CityBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asad on 2018/3/23.
 * 乐看 城市 横向 adapter
 */

public class LkcsRvAdapter extends RecyclerView.Adapter<LkcsRvAdapter.ViewHolder> {

    private List<CityBean.DataBean> data;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lkcsrv, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(holder.itemView).load(data.get(position).getImgSrc()).into(holder.lkcsrvIma);
        holder.lkcsrvTv.setText(data.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public void add(CityBean cityBean) {
        if (cityBean != null) data = cityBean.getData();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.lkcsrv_ima)
        ImageView lkcsrvIma;
        @BindView(R.id.lkcsrv_tv)
        TextView lkcsrvTv;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
